package com.zaofan.controller;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zaofan.utils.JsonUtils;
import com.zaofan.utils.WebUtils;

public class BaseServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5035453965360402957L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action = request.getParameter("action");
		if (WebUtils.isEmpty(action)) {
			JsonUtils.writeFailJson("参数错误,缺少action,请确认!!", response);
		} else {
			try {
				Method m = getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class);
				m.invoke(this, request, response);
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
